Documentation for class dictionary

Inherits from 	basic_object 

Properties declared in dictionary 

Class Methods declared in dictionary 
	new 

Methods declared in dictionary 
	any 
		associate(key, value) 
		at(key) 
		duplicate 
		empty 
		includes_key(key) 
		includes_value(value) 
		inspect 
		keys 
		remove_key(key) 
		rename(name) 
		size 
		values 

Class 
#begin_class
dictionary 
The class dictionary is a sub-class of the class basic_object. 
Dictionaries are used to store objects associated with a key. A dictionary is an unsorted list of tuples (key, object). To retrieve an object from the dictionary you use the key. 
A dictionary is in fact a hash table and is a very fast way to store and retrieve objects.

Ex:
d := {dictionary}:new
d:associate(#key1, 123)
d:associate(#key2, "abc")
d:associate(#key3, [1 2 3])

Dictionary d now contains three tuples. Use the key to retrieve the objects.

d:at(#key1)
returns 123
d:at(#key2)
returns "abc"
d:at(#key3)
returns [1 2 3]
#end_class

Properties 

Methods 

#begin_method
associate(key, value) 
Associates an object (value) with a symbol (key). If the key already exists in the dictionary, the value associated with the key will change. If the key does not exist in the dictionary, the tuple (key, value) will be added to the dictionary.
Ex:
d := {dictionary}:new
d:associate(#key1, 123)
d:associate(#'another key', "abc")
Dictionary d now contains two tuples.
d:associate(#key1, 234)
changes the value associated with the symbol #key1. Dictionary d still contains two tuples.
#end_method

#begin_method
at(key) 
Returns the value associated with key. If the key does not exist in the dictionary, the method returns nil.
Ex:
d := {dictionary}:new
d:associate(#key1, 123)
d:at(#key1)
returns 123
d:at(#key2)
returns nil
#end_method

#begin_method
duplicate 
Returns a new dictionary with copies of all the objects in the receiving dictionary.
Ex:
{button}:new:rename(#b1)
d := {dictionary}:new
d:associate(#key1, {button b1})
d:at(#key1)
returns {button b1}
d2 := d:duplicate
d2:at(#key1)
returns {button copy_of_b1}
#end_method

#begin_method
empty 
Removes all the (key, value) tuples in the dictionary.
Returns self.
#end_method

#begin_method
includes_key(key) 
Returns true if key is a key in the dictionary. Otherwise the method returns false.
Ex:
d := {dictionary}:new
d:associate(#key1, 123)
d:associate(#key2, "abc")
d:includes_key(#key1)
returns true
d:includes_key(#key3)
returns false
#end_method

#begin_method
includes_value(value) 
Returns true if value is a value in the dictionary. Otherwise the method returns false.
Ex:
d := {dictionary}:new
d:associate(#key1, 123)
d:associate(#key2, "abc")
d:includes_value(123)
returns true
d:includes_value("123")
returns false
#end_method

#begin_method
inspect 
Opens the directory inspector for the directory.
Return self.
#end_method

#begin_method
keys 
Returns a collection of all the keys in the dictionary.
#end_method

#begin_method
remove_key(key) 
Removes the (key, value) tuple identified by key.
Returns self.
Ex:
d := {dictionary}:new
d:associate(#key1, 123)
d:associate(#key2, "abc")
d:size
returns 2
d:remove_key(#key1)
d:size
returns 1
#end_method

#begin_method
rename(name) 
Sets the name of the dictionary object to the symbol name.
Ex:
d := {dictionary}:new
d:rename(#my_dictionary)
The dictionary d can now also be referred to as
{dictionary my_dictionary}
#end_method

#begin_method
size 
Returns the number of elements in the dictionary.
Ex:
d := {dictionary}:new
d:associate(#key1, 123)
d:associate(#key2, "abc")
d:size
returns 2
#end_method

#begin_method
values 
Returns a collection of all the values in the dictionary.
#end_method

Class Methods 

#begin_class_method
new 
Returns a new empty dictionary object.
Ex:
{dictionary}:new
#end_class_method